package io.kiki.sba.registry.server.shared.resource;

import io.kiki.sba.registry.common.model.GenericResponse;
import io.kiki.sba.registry.common.model.slot.Slots;
import io.kiki.sba.registry.server.shared.slot.SlotsRecorder;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;


@Path("openapi/v1/slot/table")
public class SlotGenericResource implements SlotsRecorder {

    private volatile Slots slotsRef = Slots.INIT;

    @GET
    @Path("/content")
    @Produces(MediaType.APPLICATION_JSON)
    public GenericResponse<Slots> Slots() {
        return new GenericResponse<Slots>().fillSucceed(slotsRef);
    }

    @GET
    @Path("/epoch")
    @Produces(MediaType.APPLICATION_JSON)
    public GenericResponse<Long> epoch() {
        long epoch = slotsRef.getEpoch();
        return new GenericResponse<Long>().fillSucceed(epoch);
    }

    @Override
    public void record(Slots slots) {
        slotsRef = slots;
    }
}
